#Setup version
FILE(STRINGS "${CMAKE_SOURCE_DIR}/VERSION" _version LIMIT_COUNT 1)
SET_IF_EMPTY(FUXI_PACKAGE_VERSION "${_version}")

#
# We expect a version number of the form "X.Y.Z", where X and Y are always
# numbers and Z is either a third number (for a release version) or a short
# string.
#
STRING(REGEX REPLACE "^([0-9]+)\\..*" "\\1"
  FUXI_VERSION_MAJOR "${FUXI_PACKAGE_VERSION}"
  )
STRING(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1"
  FUXI_VERSION_MINOR "${FUXI_PACKAGE_VERSION}"
  )

#
# If Z is not a number, replace it with "0", otherwise extract version
# number:
#
IF(FUXI_PACKAGE_VERSION MATCHES "^[0-9]+\\.[0-9]+.*\\.[0-9]+.*")
  STRING(REGEX REPLACE "^[0-9]+\\.[0-9]+.*\\.([0-9]+).*" "\\1"
    FUXI_VERSION_SUBMINOR "${FUXI_PACKAGE_VERSION}"
    )
ELSE()
  SET(FUXI_VERSION_SUBMINOR "0")
ENDIF()
SET(FUXI_VERSION ${FUXI_VERSION_MAJOR}.${FUXI_VERSION_MINOR}.${FUXI_VERSION_SUBMINOR})
message("Fuxi version:" ${FUXI_VERSION})

#Set up build type
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
set(CMAKE_BUILD_TYPE "Debug")
if( CMAKE_BUILD_TYPE STREQUAL "Debug"  )
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Os -g -Wall -Wno-unused-variable -pthread")
    set(FUXI_INSTALL_DIR Debug)
else( CMAKE_BUILD_TYPE STREQUAL "Release" )
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -pthread")
    set(FUXI_INSTALL_DIR Release)
endif()
message("Build Type:" ${CMAKE_BUILD_TYPE} ${CMAKE_CXX_FLAGS})

